var options={
	page_id:157,
	grid_id:"gridList",
	sqlname:"grid_157_company_wx_page"
};
//document ready
$(function(){
	grid1=new uniontrip.datagrid.searchEdit(options);
	
	$('#searchButton').bind('click',grid1.load);//查询操作绑定事件
	$('#addButton').bind('click', addRow);//新增行绑定事件
	$('#editButton').bind('click',grid1.editRow);//编辑按钮绑定事件
	$('#removeButton').bind('click',grid1.remove);//删除行绑定事件
	$('#saveButton').bind('click', grid1.accept);//保存datagrid绑定事件
	$('#cancelEditButton').bind('click',grid1.cancelEditing);//取消行编辑绑定事件
	$('#endEditingButton').bind('click', grid1.endEditing);//结束行编辑绑定事件
	$('#rejectButton').bind('click', grid1.rejectChanges);//撤销编辑绑定事件		
    $('#showChangesButton').bind('click',grid1.showChanges);//信息变更提示
    //初始化搜索框
    initsearch();
    initsessioninfo();
    $('#btn1').bind('click', opendlg1);
});
//初始化微页面
function opendlg1(){
	$('#dlg1').dialog('open');
}
function init1(){
	var theForm=$("#form-0");
	if (theForm.form("validate")){
		var formObject=$("#form-0").serializeObject();
		$._post("/authenticated/wpage/init",JSON.stringify(formObject),function(result){
			if(result.success){
				$.messager.alert("提示", "初始化成功！");
				$('#dlg1').dialog('close');
				grid1.load();
			}else{
				$.messager.alert("提示", "生成失败！"+result.message);
			}
			$.messager.progress('close');
		});
	}
}
/**
 * 新增一行
 */
function addRow(){
	var newRowData={id:guid(),creator_id:sessionuser.id,creator_name:sessionuser.nickname,create_time:moment().format('YYYY-MM-DD')};//初始化行数据
	grid1.grid.datagrid('append',newRowData);	
}
/**
 * 初始化搜索条件
 */
function initsearch(){
	/*$('#search-product_class_id').combotree({
		icons: [{
			iconCls:'icon-clear',
			handler:function(){
				$('#search-product_class_id').combotree('clear');
			}
		}],
	    data:grid1.combotreeDatas.product_class_id
	});
	*/
	$('#search-company_id,#company_id').combobox({
		panelHeight:200,
		editable:false,
		valueField:'code_value',
		textField:'code_name',
		icons: [{
			iconCls:'icon-clear',
			handler:function(e){
				$(e.data.target).combobox('clear');
			}
		}],
	    data:grid1.comboboxDatas.company_id
	});
}